<template>
    <el-form-item
        class="widget-view "
        v-if="element && element.key"
        :label="element.options.label"
        @click.native.stop="handleSelectWidget(index)"
    >
        <component :is="element.type" :data="element"/>
    </el-form-item>
</template>

<script>
import Template from './pc/template'
export default {
    components: {
        ...Template
    },
    props: ['element', 'select', 'index', 'data'],
    data() {
        return {
            selectWidget: this.select
        }
    },
    watch: {
        select(val) {
            this.selectWidget = val
        },
        selectWidget: {
            handler(val) {
                this.$emit('update:select', val)
            },
            deep: true
        }
    },
    mounted() {

    },
    methods: {
        goLink(type, url, query) {
            if (type === 'inline') {
                const param = query ? JSON.parse(query.replace(/'/g, '"')) : null
                this.gotoMyehrPath(url, param)
            } else {
                window.open(url)
            }
        },
        handleSelectWidget(index) {
            this.selectWidget = this.data.list[index]
        }
    }
}
</script>
